Fix UNKNOWN parameter type error for params used in expressions - #1
Closed
GavinPizza wants to merge 1 commit into
Closed
Fix UNKNOWN parameter type error for params used in expressions#1GavinPizza wants to merge 1 commit into
GavinPizza wants to merge 1 commit into
Conversation
Parameters used inside an expression (e.g. `WHERE id = $1 + 1`) could not have their type inferred by DuckDB at plan time, failing with "Could not convert DuckDB type: UNKNOWN". Deparse external parameters as CAST($n AS <type>) so DuckDB gets the type Postgres already resolved. Fixes duckdb#480.
Owner
Author
|
CI validation done (all 8 checks green). Superseded by the upstream PR: duckdb#1062 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CI-only PR on the fork to validate the branch before opening the upstream PR against duckdb/pg_duckdb.
A prepared or parameterized statement fails when a bind parameter is used inside an expression, e.g.
SELECT count(*) FROM t WHERE id = $1 + 1:pg_duckdb deparses the query and calls DuckDB
Prepare()at plan time to learn the result types. DuckDB can't infer a parameter's type inside an expression, so it staysUNKNOWNand result-type resolution fails (same root cause as duckdb#396). Since Postgres already resolved the parameter's type, we now deparse each external parameter asCAST($n AS <pgtype>)instead of a bare$n, handing DuckDB the type it needs. A regression test is included.This also changes the error for CTAS-with-a-parameter (still unsupported): the parameter now gets a type, so DuckDB fails later with "Not all parameters were bound" instead of "Could not find parameter with identifier 1" -- same clean failure, different message.
Known limitation:
jsonbparameters still fail (CAST($n AS jsonb)-- DuckDB has nojsonbtype); pre-existing, tracked in duckdb#516.Fixes duckdb#480.